<template>
  <div class="login-con">
    <div class="login">
      <div class="login-header">
      系统登陆
      </div>
      <div class="user-con">
        <div class="error-tip" v-show="tip&&userName&&password">用户名或密码不正确!</div>
        <div class="user-empty" v-show="btn && !userName">用户名不能为空!</div>
        <span class="name">用户名:</span>
        <input class="user-in" v-model="userName" type="text" required />
      </div>
      <div class="password-con">
        <div class="word-empty" v-show="btn && !password">密码不能为空!</div>
        <span class="word">密&nbsp;&nbsp;&nbsp;&nbsp;码:</span>
        <input class="password-in" v-model="password" type="password" required/>
      </div>
      <div class="login-footer"><button class="login-btn" @click="login()">登陆</button></div>
    </div>  
  </div>
</template>

<script>
  import baseUrl from '../../static/address.js' 
  export default {
    name: 'login',
    data() {
      return {
        btn: false,
        tip:false,
        userName: '',
        password: ''
      }
    },
    methods: {
      login() {
        this.btn = true;
        this.$axios.post(baseUrl.host + '/session',{
          login_name: this.userName,
          login_pwd: this.password
        }).then((res)=>{
          console.log('res',res.data);
          localStorage.setItem('token',res.data.token);
          localStorage.setItem('user_name',res.data.user_name);
          this.$router.push({
            name: 'home',
            data: {
              token: res.data.token,
              user_name: res.data.user_name
            }
          }) 
        }).catch((err)=>{
          // this.btn = true;
          this.tip = true;
          console.log(err)
        })
      }
    }
  }
</script>

<style scoped>
  .login-con {
    height:100%;
    width:100%;
    position: relative;
    /*background-color: #66AAEB;*/
    background: linear-gradient(#1F5B9A, #66AAEB);
    background: -webkit-linear-gradient(#1F5B9A, #66AAEB); 
    background: -o-linear-gradient(#1F5B9A, #66AAEB); 
    background: -moz-linear-gradient(#1F5B9A, #66AAEB);
  }
  .login {
    height:300px;
    width:500px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border: 12px solid #8BB0DB;
    border-radius: 5px;
    background-color: #185089;
  }
  .login-header {
    text-align: center;
    font-size: 25px;
    height:50px;
    line-height:50px;
    color:#F0F8FF;
  }
  .user-con{
    text-align: center;
    margin: 20px 0;
  }
  .name,.word {
    display: inline-block;
    width: 59px;
    text-align: right;
    color:#F0F8FF;
    font-size: 18px;
  }
  .password-con {
    text-align: center;
    margin: 20px 0;
  }
  .user-in,.password-in {
    font-size: 18px;
  }
  .login-footer {
    text-align: center;
    height: 50px;
    line-height: 50px;
  }
  .login-btn{
    padding: 2px 14px;
    font-size: 18px;
    background-color: #808080;
    border: 1px solid #808080;
    border-radius: 3px;
    color: #FFFFFF;
    cursor: pointer;
    /*border-bottom: 4px solid #696969;*/
  }
  /*.login-btn:visited {
     border: 1px solid #808080;
  }*/
  .user-empty,.word-empty,.error-tip{
    color: #FF0000;
  }
</style>